define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'org/orgcate/index' + location.search,
                    add_url: 'org/orgcate/add',
                    edit_url: 'org/orgcate/edit',
                    del_url: 'org/orgcate/del',
                    multi_url: 'org/orgcate/multi',
                    table: 'org_cate',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'name', title: __('Name'), operate:'LIKE'},
                        {field: 'parent_id', title: __('Parent_id'), operate:false},
                        {field: 'level', title: __('Level'), operate:false},
                        {field: 'reg_user_num', title: __('Reg_user_num'), operate:false},
                        {field: 'visitor_user_num', title: __('Visitor_user_num'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'introduce', title: __('Introduce'), operate:false},
                       /* {field: 'status', title: __('Status'), operate:false, searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},*/
                        {field: 'mobile', title: __('Mobile'), operate:'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    title: __('查看下级'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-folder-o',
                                    url: 'org/orgcate/index'+ location.search,
                                }
                            ]

                        }
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: false,
                commonSearch: false,
                search:true,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});